﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CsvViewer
{
    /// <summary>
    /// 用于筛选的条件
    /// </summary>
    public class FilterCondition
    {
        /// <summary>
        /// 目标列的列名。
        /// </summary>
        public string ColumnName { get; set; } = string.Empty;

        /// <summary>
        /// 条件类型，包括 大于、小于、等于、包含和不包含。
        /// </summary>
        public string ConditionType { get; set; } = "大于";

        /// <summary>
        /// 对比值。
        /// </summary>
        public string TargetValue { get; set; } = string.Empty;


        public bool Validate(string actValue)
        {
            bool result = false;
            switch (ConditionType)
            {
                case "大于":

                    break;
                case "等于":
                    result = actValue == TargetValue;
                    break;
                case "小于":
                    break;
                case "包含":
                    result = actValue.Contains(TargetValue);
                    break;
                case "不包含":
                    result = !actValue.Contains(TargetValue);
                    break;
                default: break;
            }

            return result;
        }

        public static bool All(string[] headers, string[] row, List<FilterCondition> conditions)
        {
            for (int i = 0; i < conditions.Count; i++)
            {
                var condition = conditions[i];
                for (int j = 0; j < row.Length; j++)
                {
                    var header = headers[j];
                    if (header != condition.ColumnName)
                        continue;
                    else if (!condition.Validate(row[j]))
                        return false;
                }
            }

            return true;
        }
    }
}
